#ifndef xSceneGraphWrite_h_h_h_h_h_h
#define xSceneGraphWrite_h_h_h_h_h_h

#include "stdafx.h"
#include "xBaseWrite.h"
#include "Math/COLLADABUMathMatrix4.h"
#include <stack>


namespace COLLADAFW
{
	class VisualScene;
}




namespace XE	
{


	class SceneGraphWriter : public xBaseWrite 
	{
	private:
		struct NodeInfo
		{
			NodeInfo( COLLADABU::Math::Matrix4 _worldTransformation)
				: worldTransformation(_worldTransformation){}
			COLLADABU::Math::Matrix4 worldTransformation;
		};

		typedef std::stack<NodeInfo> NodeInfoStack;

		typedef std::map<COLLADAFW::UniqueId, COLLADAFW::Node*> UniqueIdNodeMap;

	private:
		const COLLADAFW::VisualScene& mVisualScene;
		const xEngineWrite::LibraryNodesList& mLibraryNodesList;
		NodeInfoStack mNodeInfoStack;
		UniqueIdNodeMap mUniqueIdNodeMap;

		xSceneManager* m_pSceneMrg;

	public:

		SceneGraphWriter( xEngineWrite* ogreWriter, const COLLADAFW::VisualScene& visualScene,\
			const xEngineWrite::LibraryNodesList& libraryNodesList,xSceneManager* pxSceneMgr );

		virtual ~SceneGraphWriter();

		bool write();


	private:

		/** Disable default copy ctor. */
		SceneGraphWriter( const SceneGraphWriter& pre );

		/** Disable default assignment operator. */
		const SceneGraphWriter& operator= ( const SceneGraphWriter& pre );

		void createUniqueIdNodeMap( COLLADAFW::Node* node,const COLLADAFW::Node* pParaent );

		void createUniqueIdNodeMap( const COLLADAFW::NodePointerArray& nodes,const COLLADAFW::Node* pParaent=NULL );

		void createUniqueIdNodeMap();

		bool writeNodes(  const COLLADAFW::NodePointerArray& nodesToWriter);

		bool writeNode(  const COLLADAFW::Node* nodeToWriter);

		void storeInstanceGeometries( const COLLADAFW::InstanceGeometryPointerArray& instanceGeometries, 
			const COLLADABU::Math::Matrix4& worldMatrix ,const xString& name);

		void writeInstanceNodes( const COLLADAFW::InstanceNodePointerArray& instanceNodes);


	};





}




#endif 





